# coding:utf-8

import os
import sys

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.extend([BASE_DIR, ])
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "finance_c2c.settings")

import django

django.setup()

from apps.user_operation.models import UserProfile
from apps.coffee.models import Channel


# 生成用户  *******重要********* 用着呢
def create_user(channel_key):
    print(channel_key)
    channel_instance = Channel.objects.get(key=channel_key)
    user, created = UserProfile.objects.get_or_create(mobile=channel_key, username=channel_key)
    if not created:
        raise Exception("用户信息不唯一")
    user.coffee_channel = channel_instance
    user.is_coffee_manager = True
    user.coffee_new_user = False
    user.is_coffee_admin = True
    user.save()


def create_kwargs():
    channel_key_list = []
    key = "NJBank-BJ-0"
    for i in range(1, 16):
        if i < 10:
            channel_key = f"{key}0{i}"
        else:
            channel_key = f"{key}{i}"
        channel_key_list.append(channel_key)
    return channel_key_list


if __name__ == '__main__':
    # channel_keys = create_kwargs()
    # print(channel_keys)
    channel_keys = ["NJBank-BJ-000"]
    for i in channel_keys:
        create_user(i)
